/**
 * 
 */
define(function (require, exports, module) {
	var Grid = require("grid");
	var aw = require("ajaxwrapper");
	var Dialog = require("dialog");
	var store =require("store");
	var activeUser = store.get("user");
	var procDestnBuilding = require("../store/procDestnBuilding");
    var instance = {
        initComponent: function (params,widget) {
        	var grid = new Grid({
        		parentNode:".J-grid",
        		url:"api/destnbuilding/query",
        		params:function(){
        			return{
        				"orgBuilding.servicePoint.pkServicePoint" : widget.get("subnav").getValue("servicePoint"),
        				fetchProperties:procDestnBuilding.fetchProperties
        			}
        		},
        		model:{
        			columns :[{
        				name:"orgBuilding.name",
						label:"楼宇名称"
        			},{
        				name:"destination.name",
						label:"所属目的地"
        			},{
        				name:"orgBuilding.floors",
						label:"总层数"
        			},{
        				name:"orgBuilding.roomCount",
						label:"房间总数"
        			},{
        				name:"show",
        				label:"操作",
        				format:"button",
        				formatparams:[{
        					id:"edit",
        					icon:"icon-edit",
        					handler:function(index,data,rowEle){
        						widget.get("subnav").setValue("servicePoint",data.orgBuilding.servicePoint.pkServicePoint);
        						widget.get("subnav").hide(["search","add","servicePoint"]).show(["return"]);	
        						widget.get("form").setData(data);
        						
        						widget.get("form").setData("orgBuilding",[{pkOrgBuilding:data.orgBuilding.pkOrgBuilding,name:data.orgBuilding.name}]);
        						widget.get("form").setValue("orgBuilding",data.orgBuilding.pkOrgBuilding);	
        								
        						widget.get("form").setValue("floors",data.orgBuilding.floors);
        						widget.get("form").setValue("roomCount",data.orgBuilding.roomCount);
        						widget.hide([".J-grid"]).show([".J-form"]);
        						//widget.get("form").reset();
        						widget.get("form").setValue("servicePoint",widget.get("subnav").getValue("servicePoint"));
        						
        						
//		        						var form = widget.get("form");
//		        						form.setData(data);
//		        						form.setValue("servicePoint",data.orgBuilding.servicePoint.pkServicePoint);
//		        						form.setValue("servicePoint",widget.get("subnav").getValue("servicePoint"));
//		        						
        						
        					}
        				},{
        					id:"delete",
							icon:"icon-remove",
							handler:function(index,data,rowEle){
								aw.del("api/destnbuilding/"+data.pkDestnBuilding+"/delete",function() {
									grid.refresh();
								});	
							}
        				}]
        				
        			}]
        		
        		}
        	});
        	widget.set("grid",grid);
        }
    };
    module.exports = instance;
});


